package eightDataType;

import org.apache.log4j.Logger;
import org.junit.Test;

public class IntDemo {
	private static final Logger logger = Logger.getLogger(IntDemo.class);
	static final int FLAG_IN_USE = 1 << 0;
	public static void main(String[] args) {
		System.out.println("int max: 2<sup>31</sup>-1. 4byte 4*8-1 31位1位是符号位。 :"+Integer.MAX_VALUE);
		System.out.println("int min: -2<sup>31</sup>. :"+Integer.MIN_VALUE);

		int a = 127;
		int b = 127;
		System.out.println(a+"a==b int: "+(a==b));//true
		Integer aInteger= 128; //127 true 128 false
		Integer bInteger= 128;

		System.out.println(aInteger+"a==b Integer: "+(aInteger==bInteger)+"   +aInteger.hashCode:"+aInteger.hashCode()+"  bInteger.hashCode:"+bInteger.hashCode());//true
		System.out.println("Integer a.equals(b):"+aInteger.equals(bInteger));//true

		System.out.println("FLAG_IN_USE:"+FLAG_IN_USE);
		try {
			int abc = Integer.parseInt("abc");// null ，""， "abc"， 都一样 java.lang.NumberFormatException
		}catch (Exception e){
			e.printStackTrace();
		}

		System.out.println((-8>>1)+"--"+(0>>1));
		System.out.println(Integer.parseInt("-23"));
//		compareIntInteger();
//		In in = new In();
//		System.out.println(in.getA());
//		int k = 0;
//		System.out.println("KKKK===" + (k++));// 运行完成后 +1
//		int k2 = 0;
//		System.out.println("KKKK2===" + (++k2));// 先 +1

		System.out.println(Integer.MAX_VALUE );
		System.out.println(Integer.toBinaryString( (int)System.currentTimeMillis()));
		System.out.println( Integer.toBinaryString((int)System.currentTimeMillis() & Integer.MAX_VALUE) );
//		System.out.println( System.currentTimeMillis() & 0x000007fffffff );
	}

	private static void compareIntInteger() {
		int a=129;
		Integer integer = new Integer(-129);
		Integer integer2 = new Integer(129);
		System.out.println(integer);
		System.out.println(a==integer);
		System.out.println("integer2== "+(integer2==integer));
		System.out.println("integer2equals "+integer2.equals(integer));
	}

	//max number  % n
	@Test
	public void  quyu(){
		System.out.println("(Integer.MAX_VALUE + 10)%Integer.MAX_VALUE: "+(Integer.MAX_VALUE + 10)%Integer.MAX_VALUE);// -2147483639

		System.out.println("(-5)%10: "+(-5)%10);
	}

	//与或非 1、&=   与运算  二进制中，只有同为1才是1
	@Test
	public void same(){
		int origin = 0b10;
		int res = 0b111;
		logger.info("same1: "+(origin&res));
		origin&=res;
		logger.info("same2: "+(origin));
	}

	///2、|=   非运算  二进制中只要一个为1就为1
	@Test
	public void all(){
		int origin = 0b10;
		int res = 0b111;
		logger.info("all: "+res);
		logger.info("all1: "+(origin|res));
		origin|=res;
		logger.info("all2: "+(origin));
	}

}

class In {
	Integer a;
	int intb;

	public Integer getA() {
		return a;
	}

	public void setA(Integer a) {
		this.a = a;
	}

	public int getIntb() {
		return intb;
	}

	public void setIntb(int intb) {
		this.intb = intb;
	}

}
